using IcsSEMCtrl.Global;
using IcsSEMCtrl.Util.Client;
using Lifter.Device;
using Lifter.Utility;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Configuration;
using System.IO;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace Lifter.Gui.Monitor.Panels
{
    public class InformHost : InformLogMenu
    {
        private delegate void LogReadDelegate();
        private delegate void AddDataGrid(string readString);
        private Thread threadSearch = null;
        private IContainer components = null;
        private Panel panelProgress;
        private Label labelMessage;
        private Sunny.UI.UIPanel panelSearch;
        private Sunny.UI.UISymbolButton buttonSearch;
        private Sunny.UI.UIPanel uiPanel;
        private Sunny.UI.UIMarkLabel uiMarkLabel3;
        private Sunny.UI.UIComboBox ToDate;
        private Sunny.UI.UIDatePicker selectDay;
        private Sunny.UI.UIComboBox fromDate;
        private Sunny.UI.UIMarkLabel uiMarkLabel1;
        private Sunny.UI.UIMarkLabel lbStartTime;
        private RichTextBox richTextHost;
        public InformHost()
        {
            this.InitializeComponent();
            this.InitializeDataGrid();
            this.selectDay.Value = DateTime.Now;
        }
        private void InitializeDataGrid()
        {
            try
            {
            }
            catch (Exception)
            {
            }
        }
        private void buttonSearch_Click(object sender, EventArgs e)
        {
            if (this.threadSearch == null)
            {
                this.threadSearch = new Thread(new ThreadStart(this.DebugLogRead));
            }
            if (this.threadSearch.ThreadState != ThreadState.Running)
            {
                if (this.threadSearch.ThreadState == ThreadState.Stopped)
                {
                    this.threadSearch = new Thread(new ThreadStart(this.DebugLogRead));
                    this.threadSearch.Start();
                }
                else if (this.threadSearch.ThreadState == ThreadState.Stopped)
                {
                    this.threadSearch.Start();
                }
                else if (this.threadSearch.ThreadState == ThreadState.Unstarted)
                {
                    this.threadSearch.Start();
                }
            }
        }
        private void Search()
        {
            base.BeginInvoke(new InformHost.LogReadDelegate(this.DebugLogRead));
        }
        private void StartSearch()
        {
            this.panelProgress.BringToFront();
            this.labelMessage.Text = "正在查询数据，请稍等.";
            this.richTextHost.Clear();
            this.richTextHost.Enabled = false;
            this.panelSearch.Enabled = false;
        }
        private void EndSearch()
        {
            this.panelSearch.Enabled = true;
            this.richTextHost.Enabled = true;
            this.panelProgress.SendToBack();
        }
        private void StartSave()
        {
            this.panelProgress.BringToFront();
            this.richTextHost.Enabled = false;
            this.panelSearch.Enabled = false;
        }
        private void EndSave()
        {
            this.panelSearch.Enabled = true;
            this.panelSearch.Enabled = true;
            this.richTextHost.Enabled = true;
            this.panelProgress.SendToBack();
        }
        private void DebugLogRead()
        {
            base.BeginInvoke(new InformHost.LogReadDelegate(this.StartSearch));
            try
            {
                string path = AppDomain.CurrentDomain.BaseDirectory + "HOSTLOG\\SECS-II\\" + this.selectDay.Text;
                List<FileInfo> filesForReading = this.GetFilesForReading(path);
                foreach (FileInfo current in filesForReading)
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    using (StreamReader streamReader = new StreamReader(new FileStream(current.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
                    {
                        if (streamReader != null && current.Length != 0L)
                        {
                            stringBuilder = new StringBuilder(streamReader.ReadToEnd());
                            base.BeginInvoke(new InformHost.AddDataGrid(this.AddLogData), new object[]
                            {
                                stringBuilder.ToString()
                            });
                        }
                    }
                }
            }
            catch
            {
            }
            base.BeginInvoke(new InformHost.LogReadDelegate(this.EndSearch));
        }
        private void AddLogData(string readString)
        {
            this.richTextHost.AppendText(readString);
        }
        private List<FileInfo> GetFilesForReading(string path)
        {
            FileInfo[] files = new DirectoryInfo(path).GetFiles("*.txt", SearchOption.AllDirectories);
            List<FileInfo> list = new List<FileInfo>();
            int startNum = string.IsNullOrEmpty(this.fromDate.Text) ? 0 : Convert.ToInt32(this.fromDate.Text);
            int toNum = string.IsNullOrEmpty(this.ToDate.Text) ? 24 : Convert.ToInt32(this.ToDate.Text);
            foreach (FileInfo item in files)
            {
                string num = item.Name.Substring(0, 2);
                int fileNum = Convert.ToInt32(num);

                if (startNum <= fileNum && fileNum <= toNum)
                {
                    list.Add(item);
                }
            }
            return list;
        }
        protected override void Dispose(bool disposing)
        {
            if (disposing && this.components != null)
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }
        private void InitializeComponent()
        {
            this.panelProgress = new System.Windows.Forms.Panel();
            this.labelMessage = new System.Windows.Forms.Label();
            this.richTextHost = new System.Windows.Forms.RichTextBox();
            this.panelSearch = new Sunny.UI.UIPanel();
            this.uiMarkLabel3 = new Sunny.UI.UIMarkLabel();
            this.ToDate = new Sunny.UI.UIComboBox();
            this.selectDay = new Sunny.UI.UIDatePicker();
            this.fromDate = new Sunny.UI.UIComboBox();
            this.uiMarkLabel1 = new Sunny.UI.UIMarkLabel();
            this.lbStartTime = new Sunny.UI.UIMarkLabel();
            this.buttonSearch = new Sunny.UI.UISymbolButton();
            this.uiPanel = new Sunny.UI.UIPanel();
            this.panelProgress.SuspendLayout();
            this.panelSearch.SuspendLayout();
            this.uiPanel.SuspendLayout();
            this.SuspendLayout();
            // 
            // panelProgress
            // 
            this.panelProgress.BackColor = System.Drawing.SystemColors.ControlLight;
            this.panelProgress.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.panelProgress.Controls.Add(this.labelMessage);
            this.panelProgress.Location = new System.Drawing.Point(218, 166);
            this.panelProgress.Name = "panelProgress";
            this.panelProgress.Padding = new System.Windows.Forms.Padding(2);
            this.panelProgress.Size = new System.Drawing.Size(509, 55);
            this.panelProgress.TabIndex = 15;
            // 
            // labelMessage
            // 
            this.labelMessage.BackColor = System.Drawing.Color.RoyalBlue;
            this.labelMessage.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.labelMessage.Dock = System.Windows.Forms.DockStyle.Fill;
            this.labelMessage.Font = new System.Drawing.Font("Arial", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.labelMessage.ForeColor = System.Drawing.Color.MistyRose;
            this.labelMessage.Location = new System.Drawing.Point(2, 2);
            this.labelMessage.Name = "labelMessage";
            this.labelMessage.Size = new System.Drawing.Size(503, 49);
            this.labelMessage.TabIndex = 0;
            this.labelMessage.Text = "";
            this.labelMessage.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // richTextHost
            // 
            this.richTextHost.AutoWordSelection = true;
            this.richTextHost.BackColor = System.Drawing.Color.AliceBlue;
            this.richTextHost.BulletIndent = 5;
            this.richTextHost.Dock = System.Windows.Forms.DockStyle.Fill;
            this.richTextHost.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.richTextHost.ForeColor = System.Drawing.Color.Black;
            this.richTextHost.Location = new System.Drawing.Point(0, 0);
            this.richTextHost.Name = "richTextHost";
            this.richTextHost.ReadOnly = true;
            this.richTextHost.Size = new System.Drawing.Size(974, 575);
            this.richTextHost.TabIndex = 16;
            this.richTextHost.Text = "";
            // 
            // panelSearch
            // 
            this.panelSearch.Controls.Add(this.uiMarkLabel3);
            this.panelSearch.Controls.Add(this.ToDate);
            this.panelSearch.Controls.Add(this.selectDay);
            this.panelSearch.Controls.Add(this.fromDate);
            this.panelSearch.Controls.Add(this.uiMarkLabel1);
            this.panelSearch.Controls.Add(this.lbStartTime);
            this.panelSearch.Controls.Add(this.buttonSearch);
            this.panelSearch.Dock = System.Windows.Forms.DockStyle.Bottom;
            this.panelSearch.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.panelSearch.Location = new System.Drawing.Point(0, 575);
            this.panelSearch.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            this.panelSearch.MinimumSize = new System.Drawing.Size(1, 1);
            this.panelSearch.Name = "panelSearch";
            this.panelSearch.Radius = 1;
            this.panelSearch.Size = new System.Drawing.Size(974, 40);
            this.panelSearch.TabIndex = 23;
            this.panelSearch.Text = null;
            this.panelSearch.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
            this.panelSearch.ZoomScaleRect = new System.Drawing.Rectangle(0, 0, 0, 0);
            // 
            // uiMarkLabel3
            // 
            this.uiMarkLabel3.AutoSize = true;
            this.uiMarkLabel3.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.uiMarkLabel3.Location = new System.Drawing.Point(404, 9);
            this.uiMarkLabel3.Name = "uiMarkLabel3";
            this.uiMarkLabel3.Padding = new System.Windows.Forms.Padding(5, 0, 0, 0);
            this.uiMarkLabel3.Size = new System.Drawing.Size(79, 22);
            this.uiMarkLabel3.TabIndex = 102;
            this.uiMarkLabel3.Text = "结束小时";
            this.uiMarkLabel3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.uiMarkLabel3.ZoomScaleRect = new System.Drawing.Rectangle(0, 0, 0, 0);
            // 
            // ToDate
            // 
            this.ToDate.DataSource = null;
            this.ToDate.FillColor = System.Drawing.Color.White;
            this.ToDate.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.ToDate.Items.AddRange(new object[] {
            "00",
            "01",
            "02",
            "03",
            "04",
            "05",
            "06",
            "07",
            "08",
            "09",
            "10",
            "12",
            "13",
            "14",
            "15",
            "16",
            "17",
            "18",
            "19",
            "20",
            "21",
            "22",
            "23",
            "24"});
            this.ToDate.Location = new System.Drawing.Point(490, 6);
            this.ToDate.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            this.ToDate.MinimumSize = new System.Drawing.Size(63, 0);
            this.ToDate.Name = "ToDate";
            this.ToDate.Padding = new System.Windows.Forms.Padding(0, 0, 30, 2);
            this.ToDate.Size = new System.Drawing.Size(77, 29);
            this.ToDate.TabIndex = 101;
            this.ToDate.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
            this.ToDate.Watermark = "";
            this.ToDate.ZoomScaleRect = new System.Drawing.Rectangle(0, 0, 0, 0);
            // 
            // selectDay
            // 
            this.selectDay.FillColor = System.Drawing.Color.White;
            this.selectDay.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.selectDay.Location = new System.Drawing.Point(81, 4);
            this.selectDay.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            this.selectDay.MaxLength = 10;
            this.selectDay.MinimumSize = new System.Drawing.Size(63, 0);
            this.selectDay.Name = "selectDay";
            this.selectDay.Padding = new System.Windows.Forms.Padding(0, 0, 30, 2);
            this.selectDay.Size = new System.Drawing.Size(140, 32);
            this.selectDay.SymbolDropDown = 61555;
            this.selectDay.SymbolNormal = 61555;
            this.selectDay.TabIndex = 98;
            this.selectDay.Text = "2024-03-25";
            this.selectDay.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
            this.selectDay.Value = new System.DateTime(2024, 3, 25, 15, 6, 10, 444);
            this.selectDay.Watermark = "";
            this.selectDay.ZoomScaleRect = new System.Drawing.Rectangle(0, 0, 0, 0);
            // 
            // fromDate
            // 
            this.fromDate.DataSource = null;
            this.fromDate.FillColor = System.Drawing.Color.White;
            this.fromDate.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.fromDate.Items.AddRange(new object[] {
            "00",
            "01",
            "02",
            "03",
            "04",
            "05",
            "06",
            "07",
            "08",
            "09",
            "10",
            "12",
            "13",
            "14",
            "15",
            "16",
            "17",
            "18",
            "19",
            "20",
            "21",
            "22",
            "23",
            "24"});
            this.fromDate.Location = new System.Drawing.Point(321, 5);
            this.fromDate.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            this.fromDate.MinimumSize = new System.Drawing.Size(63, 0);
            this.fromDate.Name = "fromDate";
            this.fromDate.Padding = new System.Windows.Forms.Padding(0, 0, 30, 2);
            this.fromDate.Size = new System.Drawing.Size(77, 29);
            this.fromDate.TabIndex = 100;
            this.fromDate.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
            this.fromDate.Watermark = "";
            this.fromDate.ZoomScaleRect = new System.Drawing.Rectangle(0, 0, 0, 0);
            // 
            // uiMarkLabel1
            // 
            this.uiMarkLabel1.AutoSize = true;
            this.uiMarkLabel1.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.uiMarkLabel1.Location = new System.Drawing.Point(3, 7);
            this.uiMarkLabel1.Name = "uiMarkLabel1";
            this.uiMarkLabel1.Padding = new System.Windows.Forms.Padding(5, 0, 0, 0);
            this.uiMarkLabel1.Size = new System.Drawing.Size(79, 22);
            this.uiMarkLabel1.TabIndex = 97;
            this.uiMarkLabel1.Text = "查询时间";
            this.uiMarkLabel1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.uiMarkLabel1.ZoomScaleRect = new System.Drawing.Rectangle(0, 0, 0, 0);
            // 
            // lbStartTime
            // 
            this.lbStartTime.AutoSize = true;
            this.lbStartTime.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.lbStartTime.Location = new System.Drawing.Point(244, 9);
            this.lbStartTime.Name = "lbStartTime";
            this.lbStartTime.Padding = new System.Windows.Forms.Padding(5, 0, 0, 0);
            this.lbStartTime.Size = new System.Drawing.Size(79, 22);
            this.lbStartTime.TabIndex = 99;
            this.lbStartTime.Text = "开始小时";
            this.lbStartTime.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.lbStartTime.ZoomScaleRect = new System.Drawing.Rectangle(0, 0, 0, 0);
            // 
            // buttonSearch
            // 
            this.buttonSearch.Cursor = System.Windows.Forms.Cursors.Hand;
            this.buttonSearch.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.buttonSearch.Location = new System.Drawing.Point(574, 4);
            this.buttonSearch.MinimumSize = new System.Drawing.Size(1, 1);
            this.buttonSearch.Name = "buttonSearch";
            this.buttonSearch.Size = new System.Drawing.Size(100, 32);
            this.buttonSearch.Style = Sunny.UI.UIStyle.Custom;
            this.buttonSearch.StyleCustomMode = true;
            this.buttonSearch.Symbol = 361442;
            this.buttonSearch.TabIndex = 82;
            this.buttonSearch.Text = "查询";
            this.buttonSearch.TipsFont = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.buttonSearch.ZoomScaleRect = new System.Drawing.Rectangle(0, 0, 0, 0);
            this.buttonSearch.Click += new System.EventHandler(this.buttonSearch_Click);
            // 
            // uiPanel
            // 
            this.uiPanel.Controls.Add(this.richTextHost);
            this.uiPanel.Dock = System.Windows.Forms.DockStyle.Fill;
            this.uiPanel.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.uiPanel.Location = new System.Drawing.Point(0, 0);
            this.uiPanel.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            this.uiPanel.MinimumSize = new System.Drawing.Size(1, 1);
            this.uiPanel.Name = "uiPanel";
            this.uiPanel.Size = new System.Drawing.Size(974, 575);
            this.uiPanel.TabIndex = 24;
            this.uiPanel.Text = "uiPanel2";
            this.uiPanel.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
            this.uiPanel.ZoomScaleRect = new System.Drawing.Rectangle(0, 0, 0, 0);
            // 
            // InformHost
            // 
            this.Controls.Add(this.uiPanel);
            this.Controls.Add(this.panelSearch);
            this.Controls.Add(this.panelProgress);
            this.Name = "InformHost";
            this.Size = new System.Drawing.Size(974, 615);
            this.panelProgress.ResumeLayout(false);
            this.panelSearch.ResumeLayout(false);
            this.panelSearch.PerformLayout();
            this.uiPanel.ResumeLayout(false);
            this.ResumeLayout(false);

        }
    }
}
